package com.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import com.pojo.User;
import com.util.Constant;

@Controller
public class LoginController {
	
	private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
	
	@PostMapping("/sureLogin")
	public String login(HttpServletRequest request,String username,String password) {
		//String username = request.getParameter("username");
		//String password = request.getParameter("password");
		User user = new User(username,password);
		request.getSession().setAttribute(Constant.USER_SESSION, user);
		logger.info("用户："+user+" 登录了...");
		return "index";
	}
	
	@GetMapping("/login")
	public String jump() {
		return "login";
	}
	
	@PostMapping("/loginOut")
	public String loginOut(HttpServletRequest request) {
		request.getSession().removeAttribute(Constant.USER_SESSION);
		return "login";
	}
}